import { Injectable } from '@angular/core';
import {
  HttpEvent, HttpInterceptor, HttpHandler, HttpRequest
} from '@angular/common/http';

import { Observable } from 'rxjs';

/** Pass untouched request through to the next request handler. */
@Injectable()
export class NoopInterceptor implements HttpInterceptor {

  intercept(req: HttpRequest<any>, next: HttpHandler):
    Observable<HttpEvent<any>> {
    //request: HttpRequest<unknown>表示请求对象，包含了和请求相关的所有信息,unkonow指定请求体body的类型
    //next: HttpHandler 当将请求对象修改完成之后，将修改后的请求对象通过next中的handle方法传回真正发送请求的方法中
    let request = req.clone({
      setHeaders: {
        'sunshine-xtoken': "sunshine"
      }
    })//在请求头中增加token：1213456789
    console.log('headers')
    return next.handle(request)//将修改后的请求返回给应用
  }
}
